/**
 *
 */
package com.thx.user;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;

import com.thx.auth.User;
import com.thx.role.model.Role;

/**
 * 通过代理com.thx.user.model.User来实现com.thx.auth.User接口
 *
 * @author balancejia
 *
 */
public class UserProxy implements User {

	private com.thx.user.model.User user;

	public UserProxy(com.thx.user.model.User user) {
		this.user = user;
	}

	public void setUser(com.thx.user.model.User user) {
		this.user = user;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getUserName();
	}

	@Override
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String getUserId() {
		return user.getUserId();
	}

	@Override
	public List<String> getDepartmentId() {
		List<String> depIds = new ArrayList<String>();
		depIds.add(user.getDepartment().getDepId());
		return depIds;
	}

	@Override
	public String getTenantId() {
		return user.getComId();
	}

	@Override
	public boolean isAdmin() {
		Set<Role> roles = user.getRoles();
		for (Role role : roles) {
			String code = role.getRoleCode();
			if (code.equals("Administrator"))
				return true;
		}
		return false;
	}

}
